package org.noote.libs.robot.ai;

import java.util.ArrayList;

public class KindOfThing {

	private static long _nextId = 0;
	protected long _id = 0;
	
	KindOfThing _parent = null;
	ArrayList<KindOfThing> _siblings = new ArrayList<KindOfThing>();
	
	public KindOfThing()
	{
		this(null);
	}
	public KindOfThing(KindOfThing parent)
	{
		this._id = _getNextID();
		this._parent = parent;
	}
	
	synchronized protected long _getNextID()
	{
		return _nextId++;
	}

	protected long getKindOf()
	{
		return _id;
	}

	protected boolean isKindOf(KindOfThing kindOf)
	{
		// is kind of
		if(kindOf.getKindOf() == this._id) return true;
		
		// from direct lineage
		if(_parent != null)
		{
			if(_parent.isKindOf(kindOf)) return true;
		}
		
		return false;
	}

	protected boolean isNearKindOf(KindOfThing kindOf)
	{
		// from direct lineage
		if(isKindOf(kindOf)) return true;
		
		// from undirect siblings
		if(!_siblings.isEmpty())
		{
			for(KindOfThing sibling : _siblings)
			{
				if(sibling.isNearKindOf(kindOf)) return true;
			}
		}
		
		return false;
	}

	protected boolean isFarKindOf(KindOfThing kindOf)
	{
		// from direct lineage
		if(isKindOf(kindOf)) return true;
		
		// from undirect siblings
		if(!_siblings.isEmpty())
		{
			for(KindOfThing sibling : _siblings)
			{
				if(sibling.isFarKindOf(kindOf)) return true;
			}
		}
		
		return false;
	}

}
